package yifeng.program;

import yifeng.program.utils.Utils;

public class BubbleSort2222222 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int[] a = Utils.createIntArray(10, 1, 100);
		printArray(a);
		
		bubbleSort(a);
		
		System.out.println("After sorting:");
		printArray(a);
	}

	
	public static void bubbleSort(int[] a){
		if(a.length == 0)
			return;
		
		for(int i = 0; i < a.length - 1; i++)
			for(int j = 0; j < a.length - 1 - i; j++){
				if(a[j] > a[j+1])
					swap(a, j, j+1);
			}
	}
	
	private static void swap(int[] a, int j, int i) {
		int temp;
		temp = a[j];
		a[j] = a[i];
		a[i] = temp;
	}
	
	private static void printArray(int[] a){
		int i = 0;
		for(; i < a.length-1; i++){
			System.out.print(a[i] + "-");
		}
		System.out.println(a[i]);
	}
}
